// hotel.js
Page({
  data: {
    statusBarHeight: 0,
    navHeight: 132, // 导航栏总高度
    activeFilter: 'hotel', // 默认选中酒店筛选
    hotelList: [], // 当前显示的列表数据
    // 酒店数据
    hotelData: [
      {
        id: 1,
        title: "黑麋峰山景度假酒店",
        subtitle: "体验山林间的宁静时光",
        location: "黑麋峰森林公园内 · 距离主峰2公里",
        price: 368,
        period: "晚",
        rating: 4.8,
        reviewCount: 127,
        images: [
          "/images/景点-1.jpg",
          "/images/景点-2.jpg",
          "/images/景点-3.jpg"
        ],
        facilities: ["免费WiFi", "山景阳台", "温泉浴池"],
        host: {
          name: "李经理",
          avatar: "/images/113242511646348178.jpg",
          phone: "13800138000",
          isVerified: true
        }
      },
      {
        id: 2,
        title: "峡谷栈道观景民宿",
        subtitle: "推窗即见峡谷美景",
        location: "峡谷栈道入口 · 步行5分钟到观景台",
        price: 298,
        period: "晚",
        rating: 4.6,
        reviewCount: 89,
        images: [
          "/images/景点-2.jpg",
          "/images/景点-3.jpg",
          "/images/景点-4.jpg"
        ],
        facilities: ["观景露台", "免费停车", "24小时热水"],
        host: {
          name: "王女士",
          avatar: "/images/113242511646348178.jpg",
          phone: "13900139000",
          isVerified: true
        }
      },
      {
        id: 3,
        title: "山间小径度假别墅",
        subtitle: "独栋别墅·私享山林静谧",
        location: "山间小径深处 · 独享私密空间",
        price: 588,
        period: "晚",
        rating: 4.9,
        reviewCount: 156,
        images: [
          "/images/景点-4.jpg",
          "/images/景点-1.jpg",
          "/images/景点-2.jpg"
        ],
        facilities: ["私人花园", "烧烤区", "全景落地窗"],
        host: {
          name: "张先生",
          avatar: "/images/113242511646348178.jpg",
          phone: "13700137000",
          isVerified: true
        }
      },
      {
        id: 4,
        title: "云端露营基地",
        subtitle: "星空下的帐篷住宿体验",
        location: "黑麋峰山顶观景平台 · 海拔最高点",
        price: 188,
        period: "晚",
        rating: 4.7,
        reviewCount: 76,
        facilities: ["观星设备", "篝火区", "公共洗漱"],
        host: {
          name: "陈队长",
          avatar: "/images/113242511646348178.jpg",
          phone: "13600136000",
          isVerified: true
        }
      }
    ],
    // 餐厅数据
    restaurantData: [
      {
        id: 11,
        title: "黑麋峰农家菜馆",
        subtitle: "正宗湘菜·地道农家风味",
        location: "景区入口处 · 停车方便",
        price: 68,
        period: "人均",
        rating: 4.5,
        reviewCount: 234,
        features: ["特色土鸡", "野菜时蔬", "农家腊肉"],
        openTime: "09:00-21:00",
        phone: "0731-88888888"
      },
      {
        id: 12,
        title: "山顶茶餐厅",
        subtitle: "品茶观景·悠然时光",
        location: "主峰观景台旁 · 270度全景视野",
        price: 45,
        period: "人均",
        rating: 4.8,
        reviewCount: 156,
        features: ["云雾茶", "精致茶点", "观景座位"],
        openTime: "08:00-18:00",
        phone: "0731-99999999"
      },
      {
        id: 13,
        title: "峡谷烧烤园",
        subtitle: "户外烧烤·篝火晚会",
        location: "峡谷栈道中段 · 溪水潺潺",
        price: 85,
        period: "人均",
        rating: 4.3,
        reviewCount: 89,
        features: ["自助烧烤", "篝火晚会", "KTV包房"],
        openTime: "16:00-23:00",
        phone: "0731-77777777"
      },
      {
        id: 14,
        title: "森林咖啡屋",
        subtitle: "林间咖啡·静谧时光",
        location: "森林步道2公里处 · 鸟语花香",
        price: 35,
        period: "人均",
        rating: 4.6,
        reviewCount: 134,
        features: ["手冲咖啡", "森林氧吧", "轻音乐"],
        openTime: "10:00-20:00",
        phone: "0731-66666666"
      },
      {
        id: 15,
        title: "湘味小食堂",
        subtitle: "快餐便民·经济实惠",
        location: "游客服务中心 · 交通便利",
        price: 25,
        period: "人均",
        rating: 4.1,
        reviewCount: 298,
        features: ["快餐套餐", "湘式小炒", "经济实惠"],
        openTime: "07:00-22:00",
        phone: "0731-55555555"
      }
    ],

  },

  onLoad(options) {
    console.log('酒店住宿页面加载完成')
    this.getSystemInfo()
    // 初始化显示酒店数据
    this.setData({
      hotelList: this.data.hotelData
    })
  },

  // 获取系统信息
  getSystemInfo() {
    const systemInfo = wx.getSystemInfoSync()
    this.setData({
      statusBarHeight: systemInfo.statusBarHeight
    })
  },

  // 导航栏返回按钮点击事件
  onNavBackTap() {
    // 直接返回到首页
    wx.reLaunch({
      url: '/pages/index/index'
    })
  },

  // 导航栏高度变化事件
  onNavHeightChange(e) {
    const { totalHeight } = e.detail
    this.setData({
      navHeight: totalHeight
    })
  },

  // 菜单按钮点击
  onMenuTap() {
    wx.showToast({
      title: '菜单功能',
      icon: 'none'
    })
  },

  // 网格视图按钮点击
  onGridTap() {
    wx.showToast({
      title: '网格视图',
      icon: 'none'
    })
  },

  // 房源卡片点击
  onHotelTap(e) {
    const hotel = e.currentTarget.dataset.hotel
    console.log('点击房源:', hotel)
    wx.navigateTo({
      url: `/pages/detail/detail?type=hotel&id=${hotel.id}`
    })
  },

  // 房东头像点击
  onHostTap(e) {
    const host = e.currentTarget.dataset.host
    console.log('查看房东信息:', host)
    wx.showToast({
      title: `房东: ${host.name}`,
      icon: 'none'
    })
  },

  // 电话联系
  onCallTap(e) {
    const phone = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: phone,
      fail: () => {
        wx.showToast({
          title: '拨打电话失败',
          icon: 'none'
        })
      }
    })
  },

  // 发送消息
  onMessageTap(e) {
    const host = e.currentTarget.dataset.host
    console.log('发送消息给:', host)
    wx.showToast({
      title: '发送消息功能',
      icon: 'none'
    })
  },
  
  // 预订房间
  onBookTap(e) {
    const hotel = e.currentTarget.dataset.hotel
    console.log('预订房间:', hotel)
    wx.showModal({
      title: '预订确认',
      content: `您确定要预订"${hotel.title}"吗？价格：¥${hotel.price}/${hotel.period}`,
      confirmText: '确认预订',
      confirmColor: '#ff7e00', // 修改为橘色
      success: (res) => {
        if (res.confirm) {
          wx.showToast({
            title: '预订成功',
            icon: 'success'
          })
        }
      }
    })
  },
  
  // 筛选项点击事件
  onFilterTap(e) {
    const type = e.currentTarget.dataset.type
    console.log('筛选类型:', type)
    
    // 更新选中的筛选项和对应数据
    let listData = []
    let toastTitle = ''
    
    switch(type) {
      case 'hotel':
        listData = this.data.hotelData
        toastTitle = '显示酒店列表'
        break
      case 'restaurant':
        listData = this.data.restaurantData
        toastTitle = '显示餐厅列表'
        break
      default:
        listData = this.data.hotelData
        toastTitle = '显示酒店列表'
    }
    
    this.setData({
      activeFilter: type,
      hotelList: listData
    })
    
    wx.showToast({
      title: toastTitle,
      icon: 'none'
    })
  },

  // 餐厅卡片点击
  onRestaurantTap(e) {
    const restaurant = e.currentTarget.dataset.restaurant
    console.log('点击餐厅:', restaurant)
    wx.navigateTo({
      url: `/pages/detail/detail?type=restaurant&id=${restaurant.id}`
    })
  },


})
